package com.google.android.material.textfield;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Space;
import android.widget.TextView;
import androidx.appcompat.widget.z;
import androidx.core.widget.i;
import b.f.l.s;
import c.b.a.b.d;
import c.b.a.b.m.b;
import java.util.ArrayList;
import java.util.List;

final class f {

    /* renamed from: a  reason: collision with root package name */
    private final Context f2424a;

    /* renamed from: b  reason: collision with root package name */
    private final TextInputLayout f2425b;

    /* renamed from: c  reason: collision with root package name */
    private LinearLayout f2426c;

    /* renamed from: d  reason: collision with root package name */
    private int f2427d;
    private FrameLayout e;
    private int f;
    /* access modifiers changed from: private */
    public Animator g;
    private final float h;
    /* access modifiers changed from: private */
    public int i;
    private int j;
    private CharSequence k;
    private boolean l;
    /* access modifiers changed from: private */
    public TextView m;
    private int n;
    private ColorStateList o;
    private CharSequence p;
    private boolean q;
    private TextView r;
    private int s;
    private ColorStateList t;
    private Typeface u;

    class a extends AnimatorListenerAdapter {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ int f2428a;

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ TextView f2429b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ int f2430c;

        /* renamed from: d  reason: collision with root package name */
        final /* synthetic */ TextView f2431d;

        a(int i, TextView textView, int i2, TextView textView2) {
            this.f2428a = i;
            this.f2429b = textView;
            this.f2430c = i2;
            this.f2431d = textView2;
        }

        public void onAnimationEnd(Animator animator) {
            int unused = f.this.i = this.f2428a;
            Animator unused2 = f.this.g = null;
            TextView textView = this.f2429b;
            if (textView != null) {
                textView.setVisibility(4);
                if (this.f2430c == 1 && f.this.m != null) {
                    f.this.m.setText((CharSequence) null);
                }
                TextView textView2 = this.f2431d;
                if (textView2 != null) {
                    textView2.setTranslationY(0.0f);
                    this.f2431d.setAlpha(1.0f);
                }
            }
        }

        public void onAnimationStart(Animator animator) {
            TextView textView = this.f2431d;
            if (textView != null) {
                textView.setVisibility(0);
            }
        }
    }

    public f(TextInputLayout textInputLayout) {
        Context context = textInputLayout.getContext();
        this.f2424a = context;
        this.f2425b = textInputLayout;
        this.h = (float) context.getResources().getDimensionPixelSize(d.design_textinput_caption_translate_y);
    }

    private void F(TextView textView, Typeface typeface) {
        if (textView != null) {
            textView.setTypeface(typeface);
        }
    }

    private void H(ViewGroup viewGroup, int i2) {
        if (i2 == 0) {
            viewGroup.setVisibility(8);
        }
    }

    private boolean I(TextView textView, CharSequence charSequence) {
        return s.L(this.f2425b) && this.f2425b.isEnabled() && (this.j != this.i || textView == null || !TextUtils.equals(textView.getText(), charSequence));
    }

    private void L(int i2, int i3, boolean z) {
        if (z) {
            AnimatorSet animatorSet = new AnimatorSet();
            this.g = animatorSet;
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = arrayList;
            int i4 = i2;
            int i5 = i3;
            h(arrayList2, this.q, this.r, 2, i4, i5);
            h(arrayList2, this.l, this.m, 1, i4, i5);
            b.a(animatorSet, arrayList);
            animatorSet.addListener(new a(i3, l(i2), i2, l(i3)));
            animatorSet.start();
        } else {
            y(i2, i3);
        }
        this.f2425b.Y();
        this.f2425b.c0(z);
        this.f2425b.e0();
    }

    private boolean f() {
        return (this.f2426c == null || this.f2425b.getEditText() == null) ? false : true;
    }

    private void h(List<Animator> list, boolean z, TextView textView, int i2, int i3, int i4) {
        if (textView != null && z) {
            if (i2 == i4 || i2 == i3) {
                list.add(i(textView, i4 == i2));
                if (i4 == i2) {
                    list.add(j(textView));
                }
            }
        }
    }

    private ObjectAnimator i(TextView textView, boolean z) {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(textView, View.ALPHA, new float[]{z ? 1.0f : 0.0f});
        ofFloat.setDuration(167);
        ofFloat.setInterpolator(c.b.a.b.m.a.f1874a);
        return ofFloat;
    }

    private ObjectAnimator j(TextView textView) {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, new float[]{-this.h, 0.0f});
        ofFloat.setDuration(217);
        ofFloat.setInterpolator(c.b.a.b.m.a.f1877d);
        return ofFloat;
    }

    private TextView l(int i2) {
        if (i2 == 1) {
            return this.m;
        }
        if (i2 != 2) {
            return null;
        }
        return this.r;
    }

    private boolean t(int i2) {
        return i2 == 1 && this.m != null && !TextUtils.isEmpty(this.k);
    }

    private void y(int i2, int i3) {
        TextView l2;
        TextView l3;
        if (i2 != i3) {
            if (!(i3 == 0 || (l3 = l(i3)) == null)) {
                l3.setVisibility(0);
                l3.setAlpha(1.0f);
            }
            if (!(i2 == 0 || (l2 = l(i2)) == null)) {
                l2.setVisibility(4);
                if (i2 == 1) {
                    l2.setText((CharSequence) null);
                }
            }
            this.i = i3;
        }
    }

    /* access modifiers changed from: package-private */
    public void A(int i2) {
        this.n = i2;
        TextView textView = this.m;
        if (textView != null) {
            this.f2425b.Q(textView, i2);
        }
    }

    /* access modifiers changed from: package-private */
    public void B(ColorStateList colorStateList) {
        this.o = colorStateList;
        TextView textView = this.m;
        if (textView != null && colorStateList != null) {
            textView.setTextColor(colorStateList);
        }
    }

    /* access modifiers changed from: package-private */
    public void C(int i2) {
        this.s = i2;
        TextView textView = this.r;
        if (textView != null) {
            i.q(textView, i2);
        }
    }

    /* access modifiers changed from: package-private */
    public void D(boolean z) {
        if (this.q != z) {
            g();
            if (z) {
                z zVar = new z(this.f2424a);
                this.r = zVar;
                zVar.setId(c.b.a.b.f.textinput_helper_text);
                Typeface typeface = this.u;
                if (typeface != null) {
                    this.r.setTypeface(typeface);
                }
                this.r.setVisibility(4);
                s.g0(this.r, 1);
                C(this.s);
                E(this.t);
                d(this.r, 1);
            } else {
                s();
                x(this.r, 1);
                this.r = null;
                this.f2425b.Y();
                this.f2425b.e0();
            }
            this.q = z;
        }
    }

    /* access modifiers changed from: package-private */
    public void E(ColorStateList colorStateList) {
        this.t = colorStateList;
        TextView textView = this.r;
        if (textView != null && colorStateList != null) {
            textView.setTextColor(colorStateList);
        }
    }

    /* access modifiers changed from: package-private */
    public void G(Typeface typeface) {
        if (typeface != this.u) {
            this.u = typeface;
            F(this.m, typeface);
            F(this.r, typeface);
        }
    }

    /* access modifiers changed from: package-private */
    public void J(CharSequence charSequence) {
        g();
        this.k = charSequence;
        this.m.setText(charSequence);
        if (this.i != 1) {
            this.j = 1;
        }
        L(this.i, this.j, I(this.m, charSequence));
    }

    /* access modifiers changed from: package-private */
    public void K(CharSequence charSequence) {
        g();
        this.p = charSequence;
        this.r.setText(charSequence);
        if (this.i != 2) {
            this.j = 2;
        }
        L(this.i, this.j, I(this.r, charSequence));
    }

    /* access modifiers changed from: package-private */
    public void d(TextView textView, int i2) {
        if (this.f2426c == null && this.e == null) {
            LinearLayout linearLayout = new LinearLayout(this.f2424a);
            this.f2426c = linearLayout;
            linearLayout.setOrientation(0);
            this.f2425b.addView(this.f2426c, -1, -2);
            FrameLayout frameLayout = new FrameLayout(this.f2424a);
            this.e = frameLayout;
            this.f2426c.addView(frameLayout, -1, new FrameLayout.LayoutParams(-2, -2));
            this.f2426c.addView(new Space(this.f2424a), new LinearLayout.LayoutParams(0, 0, 1.0f));
            if (this.f2425b.getEditText() != null) {
                e();
            }
        }
        if (u(i2)) {
            this.e.setVisibility(0);
            this.e.addView(textView);
            this.f++;
        } else {
            this.f2426c.addView(textView, i2);
        }
        this.f2426c.setVisibility(0);
        this.f2427d++;
    }

    /* access modifiers changed from: package-private */
    public void e() {
        if (f()) {
            s.r0(this.f2426c, s.C(this.f2425b.getEditText()), 0, s.B(this.f2425b.getEditText()), 0);
        }
    }

    /* access modifiers changed from: package-private */
    public void g() {
        Animator animator = this.g;
        if (animator != null) {
            animator.cancel();
        }
    }

    /* access modifiers changed from: package-private */
    public boolean k() {
        return t(this.j);
    }

    /* access modifiers changed from: package-private */
    public CharSequence m() {
        return this.k;
    }

    /* access modifiers changed from: package-private */
    public int n() {
        TextView textView = this.m;
        if (textView != null) {
            return textView.getCurrentTextColor();
        }
        return -1;
    }

    /* access modifiers changed from: package-private */
    public ColorStateList o() {
        TextView textView = this.m;
        if (textView != null) {
            return textView.getTextColors();
        }
        return null;
    }

    /* access modifiers changed from: package-private */
    public CharSequence p() {
        return this.p;
    }

    /* access modifiers changed from: package-private */
    public int q() {
        TextView textView = this.r;
        if (textView != null) {
            return textView.getCurrentTextColor();
        }
        return -1;
    }

    /* access modifiers changed from: package-private */
    public void r() {
        this.k = null;
        g();
        if (this.i == 1) {
            this.j = (!this.q || TextUtils.isEmpty(this.p)) ? 0 : 2;
        }
        L(this.i, this.j, I(this.m, (CharSequence) null));
    }

    /* access modifiers changed from: package-private */
    public void s() {
        g();
        if (this.i == 2) {
            this.j = 0;
        }
        L(this.i, this.j, I(this.r, (CharSequence) null));
    }

    /* access modifiers changed from: package-private */
    public boolean u(int i2) {
        return i2 == 0 || i2 == 1;
    }

    /* access modifiers changed from: package-private */
    public boolean v() {
        return this.l;
    }

    /* access modifiers changed from: package-private */
    public boolean w() {
        return this.q;
    }

    /* access modifiers changed from: package-private */
    public void x(TextView textView, int i2) {
        FrameLayout frameLayout;
        if (this.f2426c != null) {
            if (!u(i2) || (frameLayout = this.e) == null) {
                this.f2426c.removeView(textView);
            } else {
                int i3 = this.f - 1;
                this.f = i3;
                H(frameLayout, i3);
                this.e.removeView(textView);
            }
            int i4 = this.f2427d - 1;
            this.f2427d = i4;
            H(this.f2426c, i4);
        }
    }

    /* access modifiers changed from: package-private */
    public void z(boolean z) {
        if (this.l != z) {
            g();
            if (z) {
                z zVar = new z(this.f2424a);
                this.m = zVar;
                zVar.setId(c.b.a.b.f.textinput_error);
                Typeface typeface = this.u;
                if (typeface != null) {
                    this.m.setTypeface(typeface);
                }
                A(this.n);
                B(this.o);
                this.m.setVisibility(4);
                s.g0(this.m, 1);
                d(this.m, 0);
            } else {
                r();
                x(this.m, 0);
                this.m = null;
                this.f2425b.Y();
                this.f2425b.e0();
            }
            this.l = z;
        }
    }
}
